package com.ep.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ep.entity.Dbug;
import com.ep.entity.Modular;
import com.ep.entity.Project;
import com.ep.entity.Task;
import com.ep.in.interceptor;
import com.ep.mapper.CustomerMapper;
import com.ep.mapper.DbugMapper;
import com.ep.mapper.ModularMapper;
import com.ep.mapper.ProjectMapper;

@Controller
public class ProController {

	
	@Autowired
	private ProjectMapper pr;
	
	@Autowired
	private CustomerMapper cm;
	
	@Autowired
	private ModularMapper mp;
	
	@Autowired
	private DbugMapper db;
	
	@RequestMapping("/pll")
	@ResponseBody
	public List<Map<String, String>> prAll(){
		return pr.All();
	}
	
	@RequestMapping("/cdan")
	@ResponseBody
	public List<Map<String, String>> cuAll(String cName){
		
		        return cm.cuNameAll(cName);
	}
	
	@RequestMapping("/jindu")
	@ResponseBody
	public List<Map<String, String>> jAll(int id){
		return mp.modAll(id);
	}
	
	@RequestMapping("/update")
	@ResponseBody
	public Map<String, String> update(@RequestBody Modular modular){
		Map<String, String> map=new HashMap<String, String>();
		if (mp.uodate(modular)>0) {
			map.put("status", "success");
		}else {
			map.put("status", "failed");
		}
		return map;
	}
	 @RequestMapping("/pro")
	 @ResponseBody
	 public  Map<String, String> update(@RequestBody Project project){
		 Map<String, String> map=new HashMap<String, String>();
		 System.out.println(project);
		 if (pr.up(project)>0) {
			map.put("status", "success");
		}else {
			map.put("status", "failed");
		}
		 return map;
	 }
	//创建项目
		 @RequestMapping("/pradd")
		 @ResponseBody
		 public Map<String, String> pradd(@RequestBody Project project){
			 Map<String, String> map=new HashMap<String, String>();
			 System.out.println(project);
			 if (pr.insert(project)>0) {
				map.put("status", "success");
			}else {
				map.put("status", "failed");
			}
			 return map;
		 }
//新增板块
		 @RequestMapping("/moadd")
		 @ResponseBody
		 public Map<String, String> pradd(@RequestBody Modular modular){
			 Map<String, String> map=new HashMap<String, String>();
			 System.out.println(modular);
			 if (mp.insert(modular)>0) {
				map.put("status", "success");
			}else {
				map.put("status", "failed");
			}
			 return map;
		 } 
		 
		 @RequestMapping("/one")
		 @ResponseBody
		 public List<Map<String, String>> moone(int id){
				return mp.moone(id);
			}
		 @RequestMapping("/tow")
		 @ResponseBody
		 public List<Map<String, String>> motow(int id){
				return mp.motow(id);
			}
		 @RequestMapping("/three")
		 @ResponseBody
		 public List<Map<String, String>> mothree(int id){
				return mp.mothree(id);
			}
		 @RequestMapping("/four")
		 @ResponseBody
		 public List<Map<String, String>> mofour(int id){
				return mp.mofour(id);
			}
		 @RequestMapping("/five")
		 @ResponseBody
		 public List<Map<String, String>> mofive(int id){
				return mp.mofive(id);
			}
		 
		 @RequestMapping("/oneup")
		 @ResponseBody
		 public  Map<String, String> upone(@RequestBody Modular modular){
			 Map<String, String> map=new HashMap<String, String>();
			 if (mp.oneup(modular)>0) {
				map.put("status", "success");
			}else {
				map.put("status", "failed");
			}
			 return map;
		 }
		 @RequestMapping("/towup")
		 @ResponseBody
		 public  Map<String, String> uptow(@RequestBody Modular modular){
			 Map<String, String> map=new HashMap<String, String>();
			 if (mp.towup(modular)>0) {
				map.put("status", "success");
			}else {
				map.put("status", "failed");
			}
			 return map;
		 }
		 
		 @RequestMapping("/threeup")
		 @ResponseBody
		 public  Map<String, String> upthree(@RequestBody Modular modular){
			 Map<String, String> map=new HashMap<String, String>();
			 if (mp.threeup(modular)>0) {
				map.put("status", "success");
			}else {
				map.put("status", "failed");
			}
			 return map;
		 }
		 
		 
		 @RequestMapping("/fourup")
		 @ResponseBody
		 public  Map<String, String> upfour(@RequestBody Modular modular){
			 Map<String, String> map=new HashMap<String, String>();
			 if (mp.fourup(modular)>0) {
				map.put("status", "success");
			}else {
				map.put("status", "failed");
			}
			 return map;
		 }
		 
		 
		 @RequestMapping("/fiveup")
		 @ResponseBody
		 public  Map<String, String> upfive(@RequestBody Modular modular){
			 Map<String, String> map=new HashMap<String, String>();
			 if (mp.fiveup(modular)>0) {
				map.put("status", "success");
			}else {
				map.put("status", "failed");
			}
			 return map;
		 }
		 @RequestMapping("/ad")
		 @ResponseBody
		 public Map<String, String> prdd(@RequestBody Dbug dbug){
			 Map<String, String> map=new HashMap<String, String>();
			 System.out.println(dbug);
			 if (db.insert(dbug)>0) {
				map.put("status", "success");
			}else {
				map.put("status", "failed");
			}
			 return map;
		 } 
		 
		    @RequestMapping("/fr")
			@ResponseBody
			public List<Map<String, String>> dana(int id){
				return db.idAll(id);
			}
		 
		 
}
